// src/router/index.ts
import {
  createRouter,
  createWebHashHistory,
  RouteRecordRaw,
  createWebHistory,
} from "vue-router";

export const Layout = () => import("@/layout/index.vue");

// 静态路由
export const constantRoutes: RouteRecordRaw[] = [
  {
    path: "/",
    redirect: "/main",
    component: Layout,
    meta: { hidden: false, title: "系统", icon: "el-icon-user" },
    name: "/",
    children: [
      {
        path: "main",
        component: () => import("@/views/main/index.vue"),
        name: "main",
        meta: {
          title: "系统",
          icon: "el-icon-user",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
    ],
  },
  {
    path: "/login",
    component: () => import("@/views/login/index.vue"),
    meta: { hidden: true },
  },

  {
    path: "/toolStore",
    redirect: "/toolStore/dragger",
    name: "toolStore",
    meta: {
      title: "工具商店",
      icon: "loading",
      hidden: false,
      alwaysShow: false,
      params: null,
    },
    component: Layout,
    children: [
      {
        path: "cropper",
        component: () => import("@/views/toolStore/cropper/index.vue"),
        name: "cropper",
        meta: {
          title: "图片裁剪工具",
          icon: "el-icon-user",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "dragger",
        component: () => import("@/views/toolStore/dragger/index.vue"),
        name: "dragger",
        meta: {
          title: "图片拖拽工具",
          icon: "el-icon-User",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "excel2json",
        component: () => import("@/views/toolStore/Excel2Json/index.vue"),
        name: "excel2json",
        meta: {
          title: "excel转json工具",
          icon: "el-icon-User",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "jsonContrast",
        component: () => import("@/views/toolStore/jsonContrast/index.vue"),
        name: "jsonContrast",
        meta: {
          title: "json对比工具",
          icon: "el-icon-User",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "wordToHtmlText",
        component: () => import("@/views/toolStore/wordToHtmlText/index.vue"),
        name: "wordToHtmlText",
        meta: {
          title: "word转html文本工具",
          icon: "el-icon-User",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "text2ssml",
        component: () => import("@/views/toolStore/text2ssml/index.vue"),
        name: "text2ssml",
        meta: {
          title: "ssml工具",
          icon: "el-icon-User",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "customEditor",
        component: () => import("@/views/toolStore/customEditor/index.vue"),
        name: "customEditor",
        meta: {
          title: "editor工具",
          icon: "el-icon-User",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "lowCode/landingPage",
        component: () =>
          import("@/views/toolStore/lowCode/landingPage/index.vue"),
        name: "lowCodeLandingPage",
        meta: {
          title: "LandingPage低代码",
          icon: "el-icon-User",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "lowCode/gifts",
        component: () => import("@/views/toolStore/gifts/index.vue"),
        name: "gifts",
        meta: {
          title: "gifts抽奖",
          icon: "el-icon-User",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
    ],
  },
  {
    path: "/testLearn",
    redirect: "/testLearn/learn1",
    name: "testLearn",
    meta: {
      title: "测试内容",
      icon: "loading",
      hidden: false,
      alwaysShow: false,
      params: null,
    },
    component: Layout,
    children: [
      {
        path: "learn1",
        component: () => import("@/views/testLearn/learn1.vue"),
        name: "learn1",
        meta: {
          title: "测试1",
          icon: "el-icon-user",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
    ],
  },
  // {
  //   path: "/system",
  //   redirect: "/system/menu",
  //   name: "system",
  //   meta: {
  //     title: "系统管理",
  //     icon: "loading",
  //     hidden: false,
  //     alwaysShow: false,
  //     params: null,
  //   },
  //   component: Layout,
  //   children: [
  //     {
  //       path: "menu",
  //       component: () => import("@/views/system/menu/index.vue"),
  //       name: "menu",
  //       meta: {
  //         title: "菜单管理",
  //         icon: "el-icon-User",
  //         hidden: false,
  //         keepAlive: true,
  //         alwaysShow: false,
  //         params: null,
  //       },
  //     },
  //     {
  //       path: "user",
  //       component: () => import("@/views/system/user/index.vue"),
  //       name: "user",
  //       meta: {
  //         title: "用户管理",
  //         icon: "el-icon-User",
  //         hidden: false,
  //         keepAlive: true,
  //         alwaysShow: false,
  //         params: null,
  //       },
  //     },
  //     {
  //       path: "role",
  //       component: () => import("@/views/system/role/index.vue"),
  //       name: "role",
  //       meta: {
  //         title: "角色管理",
  //         icon: "el-icon-User",
  //         hidden: false,
  //         keepAlive: true,
  //         alwaysShow: false,
  //         params: null,
  //       },
  //     },
  //     {
  //       path: "dept",
  //       component: () => import("@/views/system/dept/index.vue"),
  //       name: "dept",
  //       meta: {
  //         title: "部门管理",
  //         icon: "el-icon-User",
  //         hidden: false,
  //         keepAlive: true,
  //         alwaysShow: false,
  //         params: null,
  //       },
  //     },
  //   ],
  // },
];

/**
 * 创建路由
 */
const router = createRouter({
  history: createWebHistory(), //createWebHashHistory(),
  routes: constantRoutes as RouteRecordRaw[],
  // 刷新时，滚动条位置还原
  scrollBehavior: () => ({ left: 0, top: 0 }),
});

/**
 * 重置路由
 */
export function resetRouter() {
  router.replace({ path: "/login" });
  location.reload();
}

export default router;
